import { Avatar, Button, Image, Space } from 'antd';
import { UserOutlined } from '@ant-design/icons';
import type { SelectProps } from 'antd';
import type { ColumnsType } from 'antd/es/table';
import userImageData from '../../data/userImageData';
import { getOptionLabel } from '../../data/statusData';

const columns = (booleanOptions: SelectProps['options'], userTypes: SelectProps['options'], onRowNumberClick: (record: any) => void) => {
  const columns: ColumnsType<any> = [
    {
      title: '#',
      dataIndex: 'id',
      key: '__row_number',
      align: 'right',
      width: 48,
      render: (text, record, index) => {
        return (
          <Button
            type="link"
            style={{ padding: 0 }}
            onClick={() => onRowNumberClick(record)}
          >
            <em>{index + 1}</em>
          </Button>
        );
      }
    },
    {
      title: '用户名',
      dataIndex: 'username',
      key: 'username',
      render: (text, record, index) => {
        return (
          <Space size={5}>
              {
                record.avatar ?
                  <Avatar
                    draggable={false}
                    src={
                      <Image
                        src={record.avatar.startsWith('/') ? record.avatar : ('/' + record.avatar)}
                        fallback={userImageData}
                        preview={false}
                      />
                    }
                    style={{ backgroundColor: '#ffffff' }}
                  /> :
                  <Avatar
                    draggable={false}
                    icon={<UserOutlined style={{ color: '#707070', fontSize: 24 }} />}
                    style={{ backgroundColor: '#ffffff' }}
                  />
              }
              {text}
          </Space>
        );
      }
    },
    {
      title: '姓名',
      dataIndex: 'name',
      key: 'name'
    },
    {
      title: '公司',
      dataIndex: 'company',
      key: 'company'
    },
    {
      title: '部门',
      dataIndex: 'department',
      key: 'department'
    },
    {
      title: '职位',
      dataIndex: 'title',
      key: 'title'
    },
    {
      title: 'Email',
      dataIndex: 'email',
      key: 'email'
    },
    {
      title: '手机',
      dataIndex: 'mobile',
      key: 'mobile'
    },
    {
      title: '电话',
      dataIndex: 'telephone',
      key: 'telephone'
    },
    {
      title: '可用',
      dataIndex: 'active',
      key: 'active',
      align: 'center',
      render: (text, record, index) => {
        return getOptionLabel(booleanOptions, typeof(text) === 'boolean' ? text.toString() : '');
      }
    },
    {
      title: '锁定',
      dataIndex: 'locked',
      key: 'locked',
      align: 'center',
      render: (text, record, index) => {
        return getOptionLabel(booleanOptions, typeof(text) === 'boolean' ? text.toString() : '');
      }
    },
    {
      title: '管理员',
      dataIndex: 'superuser',
      key: 'superuser',
      align: 'center',
      render: (text, record, index) => {
        return getOptionLabel(booleanOptions, typeof(text) === 'boolean' ? text.toString() : '');
      }
    },
    {
      title: '类型',
      dataIndex: 'type',
      key: 'type',
      render: (text, record, index) => {
        return getOptionLabel(userTypes, text);
      }
    },
    {
      title: '账号生效日期',
      dataIndex: 'effectiveDate',
      key: 'effectiveDate',
      render: (text, record, index) => {
        return text ? text.substring(0, 10) : '';
      }
    },
    {
      title: '账号过期日期',
      dataIndex: 'terminateDate',
      key: 'terminateDate',
      render: (text, record, index) => {
        return text ? text.substring(0, 10) : '';
      }
    },
    {
      title: '密码过期日期',
      dataIndex: 'passwordTerminateDate',
      key: 'passwordTerminateDate',
      render: (text, record, index) => {
        return text ? text.substring(0, 10) : '';
      }
    },
    {
      title: '需更改密码',
      dataIndex: 'needChangePassword',
      key: 'needChangePassword',
      align: 'center',
      render: (text, record, index) => {
        return getOptionLabel(booleanOptions, typeof(text) === 'boolean' ? text.toString() : '');
      }
    },
    {
      title: '最后登录时间',
      dataIndex: 'lastLoginTime',
      key: 'lastLoginTime'
    },
    {
      title: '最后登录IP',
      dataIndex: 'lastLoginIp',
      key: 'lastLoginIp'
    },
    {
      title: '密码重试次数',
      dataIndex: 'failedLoginAttempts',
      key: 'failedLoginAttempts',
      align: 'right'
    }
  ];
  return columns;
};

export default columns;
